package com.danco.training.zaneuskaya.view;

import java.util.Map;

import java.util.TreeMap;

public class Menu {

	private Map<Integer, MenuItem> menuItems;

	public Menu() {

		this.menuItems = new TreeMap<Integer, MenuItem>();

	}

	public Map<Integer, MenuItem> getMenuItems() {
		return menuItems;
	}

	public void setMenuItems(Map<Integer, MenuItem> menuItems) {
		this.menuItems = menuItems;
	}

	public MenuItem getMenuItemByKey(Integer index) {
		return menuItems.get(index);
	}

	public MenuItem addMenuItem(MenuItem menuItem) {
		int lastKey = menuItems.size();
		return menuItems.put(lastKey, menuItem);
	}

	public MenuItem removeMenuItem(int index) {
		return menuItems.remove(index);

	}

	public String toString() {
		StringBuffer str = new StringBuffer("Choose option:");
		str.append(System.lineSeparator());
		menuItems.entrySet().stream().forEach((entry) -> {
			Integer currentKey = entry.getKey();
			MenuItem currentValue = entry.getValue();
			str.append(currentKey + ". " + currentValue);
			str.append(System.lineSeparator());
		});
		return str.toString();

	}

}
